﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace WinCSharp
{
    public partial class MutileThread : Form
    {
        public MutileThread()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 启动一个新的线程来操作主线程中的控件.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnRun_Click(object sender, EventArgs e)
        {
            Thread t = new Thread(process);
            t.Start();
        }
 

        private void process()
        {
            while (progressBar1.Value < progressBar1.Maximum)
            {
                Action<string> a = new Action<string>(AddValue);
                progressBar1.Invoke(a, "");
            }
        }

        private void AddValue(string s)
        {
            progressBar1.Value++;
        }

        private void MutileThread_Load(object sender, EventArgs e)
        {

        }


    }
}
